package com.jit.BluetoothKey.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.jit.BluetoothKey.R;
import com.jit.BluetoothKey.entity.InstructionsBean;
import com.jit.BluetoothKey.fragment.base.BaseFragment;
import com.jit.BluetoothKey.utils.ControlInstruction;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Administrator on 2018/1/25.
 * 控制Fragment
 */

public class ControlFragment extends BaseFragment implements View.OnClickListener {

    private ImageView acOpen;
    private ImageView acClose;
    private ImageView rise;
    private ImageView lock;
    private ImageView unlock;
    private ImageView trumpet;
    private ImageView trunk;
    private ImageView hsjOpen;
    private ImageView hsjClose;
    private ImageView lightOpen;
    private ImageView lightClose;
    private ImageView decline;
    private ImageView tcOpen;
    private ImageView tcClose;

    @Override
    protected int getLayoutId() {

        return R.layout.fragent_control;
    }


    @Override
    protected void initView() {
        super.initView();

        acOpen = mRootView.findViewById(R.id.fragment_controller_acopen);
        acClose = mRootView.findViewById(R.id.fragment_controller_acclose);
        rise = mRootView.findViewById(R.id.fragment_controller_rise);
        decline = mRootView.findViewById(R.id.fragment_controller_decline);
        lock = mRootView.findViewById(R.id.fragment_controller_lock);
        unlock = mRootView.findViewById(R.id.fragment_controller_unlock);
        trumpet = mRootView.findViewById(R.id.fragment_controller_trumpet);
        trunk = mRootView.findViewById(R.id.fragment_controller_trunk);
        hsjOpen = mRootView.findViewById(R.id.fragment_controller_hsjopen);
        hsjClose = mRootView.findViewById(R.id.fragment_controller_hsjclose) ;
        tcOpen = mRootView.findViewById(R.id.fragment_controller_tcopen);
        tcClose = mRootView.findViewById(R.id.fragment_controller_tcclose);
        lightOpen = mRootView.findViewById(R.id.fragment_controller_lightopen);
        lightClose = mRootView.findViewById(R.id.fragment_controller_light_close);
    }

    @Override
    protected void initListner() {
        super.initListner();
        acOpen.setOnClickListener(this);
        acClose.setOnClickListener(this);
        rise.setOnClickListener(this);
        decline.setOnClickListener(this);
        lock.setOnClickListener(this);
        unlock.setOnClickListener(this);
        trumpet.setOnClickListener(this);
        trunk.setOnClickListener(this);
        hsjOpen.setOnClickListener(this);
        hsjClose.setOnClickListener(this);
        lightOpen.setOnClickListener(this);
        lightClose.setOnClickListener(this);
        tcOpen.setOnClickListener(this);
        tcClose.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.fragment_controller_acopen:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.AC_OPEN));
                break;
            case R.id.fragment_controller_acclose:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.AC_CLOSE));
                break;
            case R.id.fragment_controller_rise:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.RISE));
                break;
            case R.id.fragment_controller_decline:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.DECLINE));
                break;
            case R.id.fragment_controller_lock:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.LOCK));
                break;
            case R.id.fragment_controller_unlock:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.UNLOCK));
                break;
            case R.id.fragment_controller_trumpet:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.TRUMPET));
                break;
            case R.id.fragment_controller_trunk:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.TRUNK));
                break;
            case R.id.fragment_controller_hsjopen:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.HSJ_OPEN));
                break;
            case R.id.fragment_controller_tcopen:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.TC_OPEN));
                break;
            case R.id.fragment_controller_tcclose:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.TC_CLOSE));
                break;
            case R.id.fragment_controller_hsjclose:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.HSJ_CLOSE));
                break;
            case R.id.fragment_controller_lightopen:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.LIGHT_OPEN));
                break;
            case R.id.fragment_controller_light_close:
                EventBus.getDefault().post(new InstructionsBean(ControlInstruction.LIGHT_CLOSE));
                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this); //注销Eventbus
    }
}
